package com.jjb.www.ui.popup;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.shape.layout.ShapeRecyclerView;
import com.jjb.www.R;
import com.jjb.www.bean.PostBean;
import com.jjb.www.ui.adapter.ChoosePostAdapter;
import com.lxj.xpopup.impl.PartShadowPopupView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author CRG
 * @date :2023/11/30 13:55
 * @description:
 */
public class CustomPartShadowPopupView extends PartShadowPopupView implements BaseAdapter.OnItemClickListener{
    private ShapeRecyclerView mPopRcv;
    private List<PostBean> mList = new ArrayList<>();
    private  ChoosePostAdapter adapter;
    private OnListener mListener;
    private Integer mPersion = 0;

    public CustomPartShadowPopupView(@NonNull Context context, List<PostBean> list,Integer persion,OnListener listener) {
        super(context);
        this.mList = list;
        this.mListener = listener;
        this.mPersion = persion;
    }
    @Override
    protected int getImplLayoutId() {
        return R.layout.custom_part_shadow_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        mPopRcv = findViewById(R.id.pop_rcv);
        mPopRcv.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new ChoosePostAdapter(getContext());
        adapter.setOnItemClickListener(this);
        mPopRcv.setAdapter(adapter);


    }

    @Override
    protected void onShow() {
        super.onShow();
        adapter.setData(mList);
        adapter.setItemSel(mPersion);
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        adapter.setItemSel(position);
        mListener.onCompleted(adapter.getItem(position).getName(),position);
        dismiss();
    }

    public interface OnListener {

        /**
         * 选择完成时回调
         */
        void onCompleted( String content, Integer position);

    }
}
